﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Collections;
using TS_XY_Train_Repaire.UserCon.SysSetting;
using TS_XY_Train_Repaire.UserCon.Report;

namespace TS_XY_Train_Repaire.SysSetting
{
    public partial class Sys_Settings_Tree_Report_Main_ManaFrom : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadID = "4";
        public Sys_Settings_Tree_Report_Main_ManaFrom()
        {
            InitializeComponent();
        }
        private void Sys_Settings_Tree_Report_Main_ManaFrom_Load(object sender, EventArgs e)
        {
            _LoadTreeList();
        }

        private void Sys_Settings_Tree_Report_Main_ManaFrom_FormClosing(object sender, FormClosingEventArgs e)
        {
            TS_Win_Locomotive_MainForm.htActionItem.Remove(this.Name);
        }
        #region//--系统目录事件--//
        private void _LoadTreeList()
        {
            flp_Dep.Controls.Clear();
            gc_Main.DataSource = null;
            gc_Main.Refresh();
            gc_WorkPlace.DataSource = null;
            gc_WorkPlace.Refresh();
            DataTable _dt = new DataTable();
            tl_Tree.Nodes.Clear();
            tl_Tree.Refresh();
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            ArrayList pList = new ArrayList();
            _ls = new LeverString_SysTreeMainList();
            _ls.f_id = "M-1";
            _ls.f_name = "系统底层数据目录";
            _ls.f_imgindex = 4;
            pList.Add(_ls);
            try
            {
                string strSQL = "select * from TS_S_T_P_Tree_Main where f_deep=0 and f_del=0 and f_id="+ _LoadID;
                SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
                conn.Open();
                SqlCommand cmd = new SqlCommand(strSQL, conn);
                SqlDataReader read = cmd.ExecuteReader();
                string _strUPID = "and (";
                int i = 0;
                while (read.Read())
                {
                    _ls = new LeverString_SysTreeMainList();
                    _ls.f_id = "T" + read["f_id"].ToString();
                    _ls.f_name = read["f_name"].ToString();
                    _ls.f_parent = "M-1";
                    _ls.f_deep = read["f_deep"].ToString();
                    _ls.f_level = read["f_level"].ToString();
                    _ls.f_type = read["f_type"].ToString();
                    _ls.f_str_0 = read["f_str_0"].ToString();
                    _ls.f_str_1 = read["f_str_1"].ToString();
                    _ls.f_str_2 = read["f_str_2"].ToString();
                    _ls.f_func_0 = read["f_func_0"].ToString();
                    _ls.f_func_1 = read["f_func_1"].ToString();
                    _ls.f_func_2 = read["f_func_2"].ToString();
                    if (read["f_type"].ToString() == "0")
                    {
                        _ls.f_imgindex = 5;
                    }
                    else
                    {
                        _ls.f_imgindex = 6;
                    }
                    if (i == 0)
                    {
                        _strUPID += "(f_level like '%," + read["f_id"].ToString() + ",%')";
                    }
                    else
                    {
                        _strUPID += "or (f_level like '%," + read["f_id"].ToString() + ",%')";
                    }
                    pList.Add(_ls);
                    i++;
                }
                _strUPID += ")";
                if (_strUPID.Length > 7)
                {
                    read.Close();
                    strSQL = "select * from TS_S_T_P_Tree_Main where f_deep>0 and f_del=0 " + _strUPID + " order by f_deep,f_level,f_name asc";
                    cmd = new SqlCommand(strSQL, conn);
                    read = cmd.ExecuteReader();
                    string _UPID = "";
                    while (read.Read())
                    {
                        _ls = new LeverString_SysTreeMainList();
                        _ls.f_id = "T" + read["f_id"].ToString();
                        _ls.f_name = read["f_name"].ToString();
                        _ls.f_deep = read["f_deep"].ToString();
                        _ls.f_level = read["f_level"].ToString();
                        _ls.f_type = read["f_type"].ToString();
                        _ls.f_str_0 = read["f_str_0"].ToString();
                        _ls.f_str_1 = read["f_str_1"].ToString();
                        _ls.f_str_2 = read["f_str_2"].ToString();
                        _ls.f_func_0 = read["f_func_0"].ToString();
                        _ls.f_func_1 = read["f_func_1"].ToString();
                        _ls.f_func_2 = read["f_func_2"].ToString();
                        _UPID = read["f_level"].ToString();
                        _UPID = _UPID.Substring(0, _UPID.Length - 1);
                        _UPID = _UPID.Substring(_UPID.LastIndexOf(',') + 1);
                        _ls.f_parent = "T" + _UPID;
                        if (read["f_type"].ToString() == "0")
                        {
                            _ls.f_imgindex = 5;
                        }
                        else
                        {
                            _ls.f_imgindex = 6;
                        }
                        pList.Add(_ls);
                    }
                }
                read.Close();
                strSQL = "select *,(select count(*) from TS_S_T_P_Report_Tech where f_treeid=TS_S_T_P_Tree.f_id and f_del=0) as f_count from TS_S_T_P_Tree where f_deep=0 and f_del=0 and f_mainid in (select f_id from TS_S_T_P_Tree_Main where f_del=0 and (f_id=" + _LoadID + " or f_level like '%," + _LoadID + ",%')) order by f_deep,f_str_2 asc";
                cmd = new SqlCommand(strSQL, conn);
                read = cmd.ExecuteReader();
                while (read.Read())
                {
                    _ls = new LeverString_SysTreeMainList();
                    _ls.f_id = "R" + read["f_id"].ToString();
                    _ls.f_name = read["f_name"].ToString();
                    _ls.f_code = read["f_code"].ToString();
                    _ls.f_mainid = read["f_mainid"].ToString();
                    _ls.f_deep = read["f_deep"].ToString();
                    _ls.f_count = read["f_count"].ToString();
                    _ls.f_level = read["f_level"].ToString();
                    _ls.f_type = read["f_type"].ToString();
                    _ls.f_str_0 = read["f_str_0"].ToString();
                    _ls.f_str_1 = read["f_str_1"].ToString();
                    _ls.f_str_2 = read["f_str_2"].ToString();
                    _ls.f_func_0 = read["f_func_0"].ToString();
                    _ls.f_func_1 = read["f_func_1"].ToString();
                    _ls.f_func_2 = read["f_func_2"].ToString();
                    _ls.f_parent = "T" + read["f_mainid"].ToString();
                    if (read["f_type"].ToString() == "0")
                    {
                        _ls.f_imgindex = 5;
                    }
                    else
                    {
                        _ls.f_imgindex = 6;
                    }
                    pList.Add(_ls);
                }
                read.Close();
                strSQL = "select *,(select count(*) from TS_S_T_P_Report_Tech where f_treeid=TS_S_T_P_Tree.f_id and f_del=0) as f_count from TS_S_T_P_Tree where f_deep>0 and f_del=0 and f_mainid in (select f_id from TS_S_T_P_Tree_Main where f_del=0 and (f_id=" + _LoadID + " or f_level like '%," + _LoadID + ",%')) order by f_deep,f_str_2 asc";
                cmd = new SqlCommand(strSQL, conn);
                read = cmd.ExecuteReader();
                while (read.Read())
                {
                    _ls = new LeverString_SysTreeMainList();
                    _ls.f_id = "R" + read["f_id"].ToString();
                    _ls.f_name = read["f_name"].ToString();
                    _ls.f_code = read["f_code"].ToString();
                    _ls.f_mainid = read["f_mainid"].ToString();
                    _ls.f_count = read["f_count"].ToString();
                    _ls.f_deep = read["f_deep"].ToString();
                    _ls.f_level = read["f_level"].ToString();
                    _ls.f_type = read["f_type"].ToString();
                    _ls.f_str_0 = read["f_str_0"].ToString();
                    _ls.f_str_1 = read["f_str_1"].ToString();
                    _ls.f_str_2 = read["f_str_2"].ToString();
                    _ls.f_func_0 = read["f_func_0"].ToString();
                    _ls.f_func_1 = read["f_func_1"].ToString();
                    _ls.f_func_2 = read["f_func_2"].ToString();
                    string _UPID = read["f_level"].ToString();
                    _UPID = _UPID.Substring(0, _UPID.Length - 1);
                    _UPID = _UPID.Substring(_UPID.LastIndexOf(',') + 1);
                    _ls.f_parent = "R" + _UPID;
                    if (read["f_type"].ToString() == "0")
                    {
                        _ls.f_imgindex = 5;
                    }
                    else
                    {
                        _ls.f_imgindex = 6;
                    }
                    pList.Add(_ls);
                }
                read.Close();
                conn.Close();
                conn.Dispose();
            }
            catch
            {
            }
            tl_Tree.DataSource = pList;
        }
        private void bbi_Tree_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
            _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
            _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
            _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
            _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            uc_Sys_Settings_Tree_ManaForm _uc = new uc_Sys_Settings_Tree_ManaForm();
            _uc._tl = _ls;
            _uc._LoadType = "Add";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _ls.f_id));
            }
            else
            {
            }
        }

        private void bbi_Tree_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_Sys_Settings_Tree_ManaForm _uc = new uc_Sys_Settings_Tree_ManaForm();
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
            _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
            _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
            _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
            _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            _uc._tl = _ls;
            _uc._LoadType = "Edit";
            //_uc.Tag = _ls;
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _ls.f_id));
            }
            else
            {
            }
        }

        private void bbi_Tree_Del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string _UpID = "-1";
            try
            {
                _UpID = tl_Tree.FocusedNode.ParentNode["f_id"].ToString();
            }
            catch
            { }

            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
            _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
            _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
            _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
            _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            uc_Sys_Settings_Tree_ManaForm _uc = new uc_Sys_Settings_Tree_ManaForm();
            _uc._tl = _ls;
            _uc._LoadType = "Del";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _UpID));
            }
            else
            {
            }
        }

        private void tl_Tree_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            bbi_Level_Add.Enabled = false;
            bbi_Level_Sub_Add.Enabled = false;
            bbi_Level_Edit.Enabled = false;
            bbi_Level_Del.Enabled = false;
            bbi_Level_Sub_Add.Enabled = false;
            bbi_Level_Edit.Enabled = false;
            bbi_Level_Del.Enabled = false;
            bbi_Level_Rel.Enabled = false;
            bbi_Report_Field_Add.Enabled = false;
            bbi_Report_Field_Auth.Enabled = false;
            try
            {
                if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "M")
                {
                }
                else if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "T")
                {
                    if (tl_Tree.FocusedNode["f_type"].ToString() == "1")
                    {
                        bbi_Level_Add.Enabled = true;
                    }
                } else if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "R")
                {
                    bbi_Level_Sub_Add.Enabled = true;
                    bbi_Level_Edit.Enabled = true;
                    bbi_Level_Del.Enabled = true;
                    bbi_Report_Field_Add.Enabled = true;
                    bbi_Level_Rel.Enabled = true;
                    bbi_Report_Field_Auth.Enabled = true;
                }
            }
            catch
            {
            }
        }

        private void tl_Tree_DoubleClick(object sender, EventArgs e)
        {
            _LoadFieldList();
            _LoadRelationDep();
        }
        #endregion
        #region//--目录数据事件--//
        private void _LoadFieldList()
        {
            gc_Main.DataSource = null;
            gc_Main.Refresh();
            gc_WorkPlace.DataSource = null;
            gc_WorkPlace.Refresh();
            try
            {
                if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "R")
                {
                    string strSQL = "select * from TS_S_T_P_Report_Field where f_del=0 and f_rmid="+ tl_Tree.FocusedNode["f_id"].ToString().Substring(1) + " order by f_rull asc";
                    DataTable dt = new DataTable();
                    TS_Win_Class.FilledDataTable(strSQL, dt);
                    gc_Main.DataSource = dt;
                }
            }
            catch
            {

            }
        }
        private void bbi_Level_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
            _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
            _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
            _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
            _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            _ls.f_mainid = "Add";
            //try
            //{
            //    _ls.f_id = tl_Level.FocusedNode["f_id"].ToString();
            //    _ls.f_mainid = tl_Level.FocusedNode["f_mainid"].ToString();
            //    _ls.f_name = tl_Level.FocusedNode["f_name"].ToString();
            //    _ls.f_code = tl_Level.FocusedNode["f_code"].ToString();
            //    _ls.f_deep = tl_Level.FocusedNode["f_deep"].ToString();
            //    _ls.f_level = tl_Level.FocusedNode["f_level"].ToString();
            //    _ls.f_type = tl_Level.FocusedNode["f_type"].ToString();
            //    _ls.f_str_0 = tl_Level.FocusedNode["f_str_0"].ToString();
            //    _ls.f_str_1 = tl_Level.FocusedNode["f_str_1"].ToString();
            //    _ls.f_str_2 = tl_Level.FocusedNode["f_str_2"].ToString();
            //    _ls.f_func_0 = tl_Level.FocusedNode["f_func_0"].ToString();
            //    _ls.f_func_1 = tl_Level.FocusedNode["f_func_1"].ToString();
            //    _ls.f_func_2 = tl_Level.FocusedNode["f_func_2"].ToString();
            //}
            //catch
            //{
            //}
            _uc._ll = _ls;
            _uc._LoadType = "Add";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _uc._tl.f_id));
            }
            else
            {
            }
        }
        private void bbi_Level_Sub_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_id"].ToString();
            _ls.f_name = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_name"].ToString();
            _ls.f_deep = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_deep"].ToString();
            _ls.f_level = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_level"].ToString();
            _ls.f_type = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_2"].ToString();
            uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Sub_Add";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _uc._ll.f_id));
            }
            else
            {
            }
        }
        private void bbi_Level_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_id"].ToString();
            _ls.f_name = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_name"].ToString();
            _ls.f_deep = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_deep"].ToString();
            _ls.f_level = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_level"].ToString();
            _ls.f_type = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_2"].ToString();
            uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Edit";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _uc._ll.f_id));
            }
            else
            {
            }
        }

        private void bbi_Level_Del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string _UpID = "-1";
            try
            {
                _UpID = tl_Tree.FocusedNode.ParentNode["f_id"].ToString();
            }
            catch
            { }
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_id"].ToString();
            _ls.f_name = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_name"].ToString();
            _ls.f_deep = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_deep"].ToString();
            _ls.f_level = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_level"].ToString();
            _ls.f_type = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_type"].ToString();
            _ls.f_str_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_0"].ToString();
            _ls.f_str_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_1"].ToString();
            _ls.f_str_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_str_2"].ToString();
            _ls.f_func_0 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_0"].ToString();
            _ls.f_func_1 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_1"].ToString();
            _ls.f_func_2 = tl_Tree.FindNodeByFieldValue("f_id", "T" + tl_Tree.FocusedNode["f_mainid"].ToString())["f_func_2"].ToString();
            uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Del";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _UpID));
            }
            else
            {
            }
        }
        private void bbi_Level_Auth_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //uc_Sys_Settings_Level_Auth_ManaForm _uc = new uc_Sys_Settings_Level_Auth_ManaForm();
            //_uc._LoadID = tl_Level.FocusedNode["f_id"].ToString();
            //_uc._LoadName = tl_Level.FocusedNode["f_name"].ToString();
            //_uc.ShowDialog();
        }

        private void bbi_Level_Rel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_Report_WorkSteps_Relation_ManaForm _uc = new uc_Report_WorkSteps_Relation_ManaForm();
            _uc._LoadID = tl_Tree.FocusedNode["f_id"].ToString();
            _uc._LoadName = tl_Tree.FocusedNode["f_name"].ToString();
            _uc.ShowDialog();
            _LoadTreeList();
            tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _uc._LoadID));
        }

        #endregion
        #region//--部门关联--//
        private void _LoadRelationDep()
        {
            flp_Dep.Controls.Clear();
            try
            {
                if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0,1)=="R")
                {
                    CheckBox cb = new CheckBox();
                    string sql = "select f_id,f_name,f_depid,(select count(*) from TS_S_T_P_Report_Dep where f_del=0 and f_depid=TS_S_T_B_WorkMain_Dispatcher.f_depid and f_rmid=" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1) + ") as f_count from TS_S_T_B_WorkMain_Dispatcher where f_del=0 and f_type=(select top 1 f_type from TS_TR_PS_Work_Main where f_id in (select f_mwid from TS_TR_PS_Work_Main_Group where f_id in (select f_funcid from TS_S_T_P_Report_Tech where f_functype=1 and f_treeid="+tl_Tree.FocusedNode["f_id"].ToString().Substring(1)+")))";
                    //MessageBox.Show(sql);
                    SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd = new SqlCommand(sql, conn);
                    SqlDataReader read = cmd.ExecuteReader();
                    int i = 0;
                    while (read.Read())
                    {
                        cb = new CheckBox();
                        cb.Width = 160;
                        cb.Padding = new System.Windows.Forms.Padding(0);
                        cb.Name = "cb_" + read["f_depid"].ToString();
                        cb.Tag = read["f_depid"].ToString();
                        cb.Text = read["f_name"].ToString();
                        cb.Size =new Size(120,32);
                        if (read["f_count"].ToString() != "0") { cb.Checked = true; }
                        cb.Click += new EventHandler(cb_Click);
                        flp_Dep.Controls.Add(cb);
                        i++;
                    }
                    read.Close();
                    conn.Close();
                }
            }
            catch
            {
            }
        }

        void cb_Click(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
            {
                TS_Win_Class.MySqlCom("insert into TS_S_T_P_Report_Dep (f_rmid,f_depid,f_workerid) values("+tl_Tree.FocusedNode["f_id"].ToString().Substring(1)+"," + ((CheckBox)sender).Tag + "," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")");
            }
            else
            {
                TS_Win_Class.MySqlCom("update TS_S_T_P_Report_Dep set f_del=1 where f_depid=" + ((CheckBox)sender).Tag + " and f_rmid=" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1)+" and f_del=0");
            }
        }
        #endregion
        private void bbi_Reload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string _UpID = "0";
            try
            {
                _UpID = tl_Tree.FocusedNode["f_id"].ToString();
            }
            catch
            {
            }
            _LoadTreeList();
            try
            {
                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _UpID));
            }
            catch
            {
            }
        }

        private void gc_Main_Click(object sender, EventArgs e)
        {
            bbi_Report_Field_Edit.Enabled = false;
            bbi_Report_Field_Del.Enabled = false;
            if (gv_Main.SelectedRowsCount>0)
            {
                string strSQL = "select f_id,f_name,f_wpid,f_brief,(select case count(*) when 0 then convert(bit,0) else convert(bit,1) end from TS_S_T_P_Report_Field_WP where f_del=0 and f_rmfid=" + gv_Main.GetRowCellValue(gv_Main.GetSelectedRows()[0], "f_id").ToString() + " and f_pwpid=TS_TR_PS_Work_Main_Group_WorkPlace.f_id and f_wpid=TS_TR_PS_Work_Main_Group_WorkPlace.f_wpid)as f_check,(select f_name from TS_TR_PS_Work_Main_Group where f_id=TS_TR_PS_Work_Main_Group_WorkPlace.f_mwgid)as f_mwgname,(select f_name from TS_S_T_B_TrainDataType where f_id=TS_TR_PS_Work_Main_Group_WorkPlace.f_dtid) as f_dtname from TS_TR_PS_Work_Main_Group_WorkPlace where f_mwsid in (select f_funcid from TS_S_T_P_Report_Tech where f_functype=1 and f_treeid=" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1)+" and f_del=0) and f_del=0 order by f_mwgid,f_order asc";
                DataTable dt = new DataTable();
                TS_Win_Class.FilledDataTable(strSQL, dt);
                gc_WorkPlace.DataSource = dt;
                bbi_Report_Field_Edit.Enabled = true;
                bbi_Report_Field_Del.Enabled = true;
            }
            else
            {
                gc_WorkPlace.DataSource = null;
                gc_WorkPlace.Refresh();
            }
        }

        private void bt_Relation_Click(object sender, EventArgs e)
        {
            string strSQL = "update TS_S_T_P_Report_Field_WP set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_del=0 and f_rmfid=" + gv_Main.GetRowCellValue(gv_Main.GetSelectedRows()[0], "f_id").ToString();
            TS_Win_Class.MySqlCom(strSQL);
            for (int i = 0; i < gv_WorkPlace.RowCount; i++)
            {
                if ((Boolean)gv_WorkPlace.GetRowCellValue(i, "f_check"))
                {
                    strSQL = "insert into TS_S_T_P_Report_Field_WP(f_rmid,f_rmfid,f_pwpid,f_wpid) values(" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1) + ","+ gv_Main.GetRowCellValue(gv_Main.GetSelectedRows()[0], "f_id") + ","+ gv_WorkPlace.GetRowCellValue(i, "f_id") + ","+ gv_WorkPlace.GetRowCellValue(i, "f_wpid") + ")";
                    TS_Win_Class.MySqlCom(strSQL);
                }
            }
        }

        private void bbi_Report_Field_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserCon.Report.us_Report_Field_ManaForm _uc = new us_Report_Field_ManaForm();
            _uc._LoadID = tl_Tree.FocusedNode["f_id"].ToString().Substring(1);
            _uc._LoadType = "Add";
            _uc.ShowDialog();
            _LoadFieldList();
        }

        private void bbi_Report_Field_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserCon.Report.us_Report_Field_ManaForm _uc = new us_Report_Field_ManaForm();
            _uc._LoadID = gv_Main.GetRowCellValue(gv_Main.GetSelectedRows()[0], "f_id").ToString();
            _uc._LoadType = "Edit";
            _uc.ShowDialog();
            _LoadFieldList();
        }

        private void bbi_Report_Field_Del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserCon.Report.us_Report_Field_ManaForm _uc = new us_Report_Field_ManaForm();
            _uc._LoadID = gv_Main.GetRowCellValue(gv_Main.GetSelectedRows()[0], "f_id").ToString();
            _uc._LoadType = "Del";
            _uc.ShowDialog();
            _LoadFieldList();
        }

        private void bbi_Report_Field_Auth_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserCon.Report.us_Report_Field_Report_Auth_ManaForm _uc = new us_Report_Field_Report_Auth_ManaForm();
            _uc._LoadID = tl_Tree.FocusedNode["f_id"].ToString().Substring(1);
            _uc.ShowDialog();
        }
    }
}